home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 21 / Cream of the Crop 21 (Terry Blount) (October 1996).iso / editor / auror300.zip / FILESTAT.AML < prev    next >
Text File  |  1996-07-17  |  4KB  |  140 lines

  1. //--------------------------------------------------------------------
  2. // FILESTAT.AML
  3. // Display File/Directory Statistics, (C) 1993-1996 by nuText Systems
  4. //
  5. // (See Filestat.dox for user help)
  6. //
  7. // This macro display statistics for the current File in an edit window,
  8. // or the current File or Directory in a file manager window.
  9. //
  10. // This macro may also call the Sweep macro and Cfg\Cfgintnl.x.
  11. //
  12. // Usage:
  13. //
  14. // Select this macro from the Macro List (on the Macro menu), or run it
  15. // from the macro picklist <shift f12>.
  16. //
  17. // When called as a utility from other macros, the following parameter
  18. // may be passed:
  19. //
  20. //   arg 3: an optional filename/directory
  21. //
  22. // If a filename/directory is not passed, the user will be prompted to
  23. // enter one.
  24. //--------------------------------------------------------------------
  25.  
  26. include bootpath "define.aml"
  27.  
  28. // function to get the day of the week for a date
  29. private function getdow (year month day)
  30.  
  31.   // get the day in which the year starts using a perpetual
  32.   // calendar (0-6, 0=sunday)
  33.   startday = "5012356013456123460124560234" [year mod 28 + 1]
  34.  
  35.   // string indicating the days over 28 for each month
  36.   over28 = concat (if? (not (year mod 4)) "31" "30") "3232332323"
  37.  
  38.   // get the number of days in previous months
  39.   for i = 1 to month - 1 do
  40.     monthdays = monthdays + 28 + over28 [i]
  41.   end
  42.  
  43.   // return the day of the week for the date (0=sunday)
  44.   dow = (startday + monthdays + day - 1) mod 7
  45. end
  46.  
  47. name = arg 3
  48. if not name then
  49.   name = if? (wintype? "fmgr") (getpath (getbufname)) (getbufname)
  50. end
  51. if length name > 3 and not (locatefile name) then
  52.   return
  53. end
  54.  
  55. fullname = onname name
  56.  
  57. // directory/drive
  58. if name [0] == '\\' then
  59.   height = 6
  60.   directory = TRUE
  61.   // drive only
  62.   titled = "directories"
  63.   if length name == 3 then
  64.     title = "Drive"
  65.     driveonly = TRUE
  66.     fullname = title + ': ' + fullname:9
  67.   // directory
  68.   else
  69.     titled = "sub" + titled
  70.     title = "Directory"
  71.     height = 8
  72.   end
  73.   datedesc = "Created"
  74.   display
  75.   // get size and stats from external sweep macro
  76.   stats = runmacro (bootpath "macro\\sweep.x") '' name
  77.   size = stats [3]
  78.   leadsize = -13
  79.   name [0] = ''
  80.  
  81. //file
  82. else
  83.   height = 7
  84.   title = "File"
  85.   datedesc = "Last Modified"
  86.   size = getfileinfo name 's'
  87.   leadsize = -19
  88. end
  89.  
  90. macrofile = arg 1
  91.  
  92. // called by Lib.x when a key is entered in the dialog box
  93. function ondialog (keycode)
  94.   // macro help
  95.   if keycode == <f1> then
  96.     helpmacro macrofile
  97.   end
  98. end
  99.  
  100. // create dialog box
  101. dialog title + " Statistics" 70 height "cp"
  102.  
  103. // file/directory name
  104. writeline fullname '' 3 2
  105. gotoxy 3 4
  106.  
  107. // size
  108. writeline ((if? directory "Total ") + "Size:  "):leadsize +
  109.           (thousands size) + " bytes (" +
  110.           (thousands (getdisk 'f' name [1]) / 1048576 ) + "MB free)"
  111.  
  112. // directory contents
  113. if directory then
  114.   writeline "Contents:  ":leadsize + (thousands stats [2]) + " files, " +
  115.             (thousands stats [1]) + ' ' +
  116.             titled '' 3
  117. end
  118.  
  119. // date/time and attributes
  120. if not driveonly then
  121.  
  122.   // get the file date/time in raw format
  123.   // rawtime format = YYYYMMDDWhhmmssuu
  124.   rawtime = getfileinfo name 'r'
  125.   year    = rawtime [1:4]
  126.   month   = rawtime [5:2]
  127.   day     = rawtime [7:2]
  128.  
  129.   // get formatted date string
  130.   datestr = runmacro (bootpath "cfg\\cfgintnl.x") '' 'f'
  131.                      year month day (getdow year month day)
  132.  
  133.   writeline (datedesc + " on:  "):leadsize + datestr '' 3
  134.   writeline "Attributes:  ":leadsize +
  135.             (getfileinfo name 'a') '' 3
  136. end
  137.  
  138. // display the dialog box
  139. getdialog
  140.